/*
 * @Author: zuimo
 * @Date: 2020-11-27 15:03:12
 * @LastEditTime: 2020-11-27 17:01:10
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /demo/dataStruct/src/ts/sigleLinkList.ts
 */
var SigleLinkNode = /** @class */ (function () {
    function SigleLinkNode(element) {
        this.value = element;
        this.next = null;
    }
    return SigleLinkNode;
}());
function defaultEqual(a, b) {
    return a === b;
}
var SigleLinkList = /** @class */ (function () {
    function SigleLinkList(userEqual) {
        this.rear = null;
        this.count = 0;
        this.equals = userEqual || defaultEqual;
    }
    SigleLinkList.prototype.push = function (element) {
        // create Node
        var node = new SigleLinkNode(element);
        //  empty
        if (this.isEmpty()) {
            this.rear = node;
            this.rear.next = this.rear;
        }
        else {
            // swap 
            var current = this.rear;
            this.rear = node;
            this.rear.next = current.next;
            current.next = this.rear;
        }
        this.count++;
    };
    SigleLinkList.prototype.getFront = function () {
        return this.rear.next.value;
    };
    SigleLinkList.prototype.getRear = function () {
        return this.rear.value;
    };
    SigleLinkList.prototype.indexOf = function (element) {
        if (element === void (0) || element === null) {
            return -1;
        }
        var index = 0;
        var current = this.rear.next;
        if (current.value === element) {
            return index;
        }
        while (current !== this.rear && !this.equals(current.value, element)) {
            current = current.next;
            index++;
        }
        var resultIndex = index;
        if (current === this.rear && !this.equals(current.value, element)) {
            resultIndex = -1;
        }
        return resultIndex;
    };
    //  list foeward and back new head
    SigleLinkList.prototype.headForward = function () {
        this.rear = this.rear.next;
        return this.rear.value;
    };
    SigleLinkList.prototype.isEmpty = function () {
        return this.size() === 0;
    };
    SigleLinkList.prototype.size = function () {
        return this.count;
    };
    SigleLinkList.prototype.printf2Arr = function () {
        var linkArr = [];
        var current = this.rear.next;
        while (current !== this.rear) {
            linkArr.push(current.value);
            current = current.next;
        }
        linkArr.push(current.value);
        console.log(linkArr);
        return linkArr;
    };
    return SigleLinkList;
}());
var swipperList = new SigleLinkList();
swipperList.push(0);
swipperList.push(1);
swipperList.push(2);
swipperList.push(3);
swipperList.push(4);
swipperList.push(5);
